|
ARD2
RC2
Airbag Reference Demonstrator using MPC5604P
|
00001 00016 #include "derivative.h" 00017 #include "Compile_Options.h" 00018 #include "LIN_UART.h" 00019 /* 00020 ****************************************************************************** 00021 * Constants 00022 ****************************************************************************** 00023 */ 00025 static const LINFLEX_t catLINUARTInstances[] = 00026 { 00027 &(LINFLEX_0), &(LINFLEX_1), &(LINFLEX_2), &(LINFLEX_3) 00028 }; 00029 /* 00030 ****************************************************************************** 00031 * Globals 00032 ****************************************************************************** 00033 */ 00035 vuint8_t gau8LINUARTWordsTx[N_LIN_INSTANCES]; 00037 vuint8_t gau8LINUARTWordsRx[N_LIN_INSTANCES]; 00041 vuint8_t gau8LINUARTRxFlagHasBeenClearedByTx[N_LIN_INSTANCES]; 00043 static vuint8_t gau8LINUARTPhysicalBufferSize[N_LIN_INSTANCES]; 00045 vuint8_t* gpu8LINUARTTxBuffer[N_LIN_INSTANCES]; 00047 vuint8_t* gpu8LINUARTRxBuffer[N_LIN_INSTANCES]; 00048 /* 00049 ****************************************************************************** 00050 * u8fnUARTWrite 00051 ****************************************************************************** 00052 */ 00053 uint8_t u8fnUARTWrite(const uint8_t u8Instance, const uint8_t* pu8UARTTx, \ 00054 const uint8_t u8Size) 00055 { 00056 /* Declare local variables */ 00057 uint8_t u8Status; 00058 00059 /* We will init our local variable by starting a transmission */ 00060 u8Status = u8fnLINUARTSend(u8Instance, pu8UARTTx, u8Size); 00061 00062 if(CLEAR == u8Status) 00063 { 00064 /* If our transmission started, we will now wait for it to finish */ 00065 u8Status = u8fnWaitForUARTTxBufferToEmpty(u8Instance, SCI_TIME_OUT); 00066 /* And once we're done, we will stop the HW */ 00067 vfnEnableLINRxISR(u8Instance, CLEAR); 00068 } 00069 else 00070 { 00071 /* Nothing */ 00072 } 00073 00074 return(u8Status); 00075 } 00076 /* 00077 ****************************************************************************** 00078 * u8fnUARTRead 00079 ****************************************************************************** 00080 */ 00081 uint8_t u8fnUARTRead(const uint8_t u8Instance, const uint8_t* pu8UARTRx, \ 00082 const uint8_t u8Size) 00083 { 00084 /* Locals */ 00085 uint32_t u32TimeOut; 00086 uint8_t u8Status; 00087 00088 /* Init locals */ 00089 u32TimeOut = CLEAR; 00090 /* Also receive data using interrupts */ 00091 u8Status = u8fnLINUARTReceive(u8Instance, pu8UARTRx, TRUE); 00092 00093 if(CLEAR == u8Status) 00094 { 00095 do 00096 { 00097 /* Wait here */ 00098 u32TimeOut++; 00099 }while((SCI_TIME_OUT != u32TimeOut) && 00100 (u8Size > gau8LINUARTWordsRx[u8Instance])); 00101 00102 /* Why did we exit the loop ? */ 00103 if(CLEAR == u32TimeOut) 00104 { 00105 u8Status = UART_TIMEOUT; 00106 } 00107 else 00108 { 00109 /* We're good */ 00110 } 00111 } 00112 else 00113 { 00114 /* Nothing */ 00115 } 00116 00117 return(u8Status); 00118 } 00119 /* 00120 ****************************************************************************** 00121 * u8fnLINUARTSend 00122 ****************************************************************************** 00123 */ 00124 uint8_t u8fnLINUARTSend(const uint8_t u8Instance, const uint8_t* pu8UARTTx, \ 00125 const uint8_t u8Size) 00126 { 00127 /* Locals */ 00128 uint8_t u8Status; 00129 00130 u8Status = CLEAR; 00131 00132 /* Only proceed if there's no pending operation & we are not in config mode */ 00133 if((CLEAR == gau8LINUARTWordsTx[u8Instance]) && \ 00134 (LIN_INIT != u8fnReturnLINSMMode(u8Instance))) 00135 { 00136 /* Assign buffers to globals and enable interrupts */ 00137 gau8LINUARTWordsTx[u8Instance] = u8Size; 00138 gpu8LINUARTTxBuffer[u8Instance] = (vuint8_t*)pu8UARTTx; 00139 00140 /* Enable Data Transmission Done Interrupt */ 00141 vfnEnableLINTxISR(u8Instance, TRUE); 00142 00143 /* Transmit the first set of data */ 00144 u8Status = u8fnLINUARTSetTxData(u8Instance); 00145 } 00146 else 00147 { 00148 u8Status = UART_NOT_READY; 00149 } 00150 00151 return(u8Status); 00152 } 00153 /* 00154 ****************************************************************************** 00155 * u8fnLINUARTReceive 00156 ****************************************************************************** 00157 */ 00158 uint8_t u8fnLINUARTReceive(const uint8_t u8Instance, const uint8_t* pu8UARTRx, 00159 const uint8_t u8IsrEn) 00160 { 00161 /* Locals */ 00162 uint8_t u8Status; 00163 00164 u8Status = CLEAR; 00165 /* Only proceed if we are not in config mode */ 00166 if(LIN_INIT != u8fnReturnLINSMMode(u8Instance)) 00167 { 00168 /* Start by clearing how many bytes we have */ 00169 gau8LINUARTWordsRx[u8Instance] = CLEAR; 00170 00171 /* Now tell the global variable where to write received data */ 00172 gpu8LINUARTRxBuffer[u8Instance] = (vuint8_t*)pu8UARTRx; 00173 00174 /* Enable Rx Data Reception Complete Interrupt */ 00175 vfnEnableLINRxISR(u8Instance, u8IsrEn); 00176 } 00177 else 00178 { 00179 u8Status = UART_NOT_READY; 00180 } 00181 00182 return(u8Status); 00183 } 00184 /* 00185 ****************************************************************************** 00186 * u8fnConfigLINUARTGeneral 00187 ****************************************************************************** 00188 */ 00189 uint8_t u8fnConfigLINUARTGeneral(const LINUARTConfig_t* tLINUARTConfig) 00190 { 00191 /* Declare locals */ 00192 uint8_t u8Status; 00193 uint8_t u8Instance; 00194 LINFLEX_t tMyLINFLEX; 00195 00196 /* Init locals */ 00197 u8Status = CLEAR; 00198 u8Instance = (uint8_t)tLINUARTConfig->P.Instance; 00199 00200 /* Before anything can happen, we need to know to what instance we're */ 00201 /* going to talk to. */ 00202 tMyLINFLEX = catLINUARTInstances[u8Instance]; 00203 00204 /* We need to go into INIT */ 00205 u8Status = u8fnChangeSMModeLINUART(u8Instance, (uint8_t)LIN_INIT); 00206 if(CLEAR == u8Status) 00207 { 00208 /* Configure the module as an UART before continuing */ 00209 tMyLINFLEX->UARTCR.B.UART = TRUE; 00210 00211 /* Enable transmission and reception */ 00212 tMyLINFLEX->UARTCR.B.TXEN = TRUE; 00213 tMyLINFLEX->UARTCR.B.RXEN = TRUE; 00214 00215 /* Set the baud-rate */ 00216 tMyLINFLEX->LINFBRR.B.DIV_F = tLINUARTConfig->P.BaudRateFraction; 00217 tMyLINFLEX->LINIBRR.B.DIV_M = tLINUARTConfig->P.BaudRateMantissa; 00218 00219 /* Set buffer sizes */ 00220 tMyLINFLEX->UARTCR.B.TDFL = tLINUARTConfig->P.TxBufferSize; 00221 tMyLINFLEX->UARTCR.B.RDFL = tLINUARTConfig->P.RxBufferSize; 00222 00223 /* Also, remember these */ 00224 gau8LINUARTPhysicalBufferSize[u8Instance] = (uint8_t)\ 00225 (((tLINUARTConfig->P.TxBufferSize + 1u) << BITS_IN_NIBBLE) | \ 00226 (tLINUARTConfig->P.RxBufferSize + 1u)); 00227 00228 /* Set Parity checks */ 00229 tMyLINFLEX->UARTCR.B.OP = tLINUARTConfig->P.OddParityEn; 00230 tMyLINFLEX->UARTCR.B.PCE = tLINUARTConfig->P.ParityCheckEn; 00231 00232 /* Set Word Size */ 00233 tMyLINFLEX->UARTCR.B.WL = tLINUARTConfig->P.WordSizeIs8Bits; 00234 00235 00236 if(TRUE == tLINUARTConfig->P.Enable) 00237 { 00238 u8Status = u8fnChangeSMModeLINUART(u8Instance, \ 00239 (uint8_t)LIN_IDLE); 00240 /* Make sure that the counters are set to 0 */ 00241 gau8LINUARTWordsTx[u8Instance] = CLEAR; 00242 gau8LINUARTWordsRx[u8Instance] = CLEAR; 00243 } 00244 else 00245 { 00246 /* Stay in current mode, and disable TX AND RX */ 00247 tMyLINFLEX->UARTCR.B.TXEN = CLEAR; 00248 tMyLINFLEX->UARTCR.B.RXEN = CLEAR; 00249 } 00250 } 00251 else 00252 { 00253 /* Nothing, exit and flag */ 00254 } 00255 00256 return(u8Status); 00257 } 00258 /* 00259 ****************************************************************************** 00260 * u8fnLINUARTSetTxData 00261 ****************************************************************************** 00262 */ 00263 static uint8_t u8fnLINUARTSetTxData(uint8_t u8Instance) 00264 { 00265 /* Declare locals */ 00266 uint8_t u8Status; 00267 uint8_t u8UARTBufferSize; 00268 00269 /* Init locals */ 00270 u8Status = CLEAR; 00271 00272 /* Define what the buffer size for the UART is: we'll need this later */ 00273 u8UARTBufferSize = gau8LINUARTPhysicalBufferSize[u8Instance] >> BITS_IN_NIBBLE; 00274 00275 if(CLEAR < gau8LINUARTWordsTx[u8Instance] / u8UARTBufferSize) 00276 { 00277 u8Status = u8fnLINWriteTxBuffer(u8Instance, u8UARTBufferSize); 00278 }/* End of IF */ 00279 else 00280 { 00281 /* We need to redefine the size of our Buffer size */ 00282 u8UARTBufferSize = gau8LINUARTWordsTx[u8Instance]; 00283 00284 /* And we need to feed this new size to our buffer */ 00285 if(CLEAR == u8fnChangeSMModeLINUART(u8Instance, (uint8_t)LIN_INIT)) 00286 { 00287 catLINUARTInstances[u8Instance]->UARTCR.B.TDFL = u8UARTBufferSize - 1u; 00288 if(CLEAR == u8fnChangeSMModeLINUART(u8Instance, (uint8_t)LIN_DATA_TX_RX)) 00289 { 00290 u8Status = u8fnLINWriteTxBuffer(u8Instance, u8UARTBufferSize); 00291 } 00292 else 00293 { 00294 u8Status = UART_NOT_READY; 00295 } 00296 } 00297 else 00298 { 00299 /* Flag it as an error and exit */ 00300 u8Status = UART_NOT_READY; 00301 } 00302 }/* End of ELSE */ 00303 00304 return(u8Status); 00305 } 00306 /* 00307 ****************************************************************************** 00308 * u8fnLINUARTGetDataNoIsr 00309 ****************************************************************************** 00310 */ 00311 uint8_t u8fnLINUARTGetDataNoIsr(uint8_t u8Instance) 00312 { 00313 /* used to get data without using ISRs */ 00314 /* Locals */ 00315 uint8_t u8Status; 00316 00317 /* Init locals */ 00318 u8Status = CLEAR; 00319 00320 /* Since the receive flag is also cleared when the Tx flag is cleared, */ 00321 /* we will check both for the state of the HW flag and a SW flag set */ 00322 /* by the Tx Isr in case this happens. */ 00323 if((catLINUARTInstances[u8Instance]->UARTSR.B.DRF == TRUE) || 00324 (gau8LINUARTRxFlagHasBeenClearedByTx[u8Instance] == TRUE)) 00325 { 00326 /* Clear flags */ 00327 catLINUARTInstances[u8Instance]->UARTSR.B.DRF = TRUE; 00328 gau8LINUARTRxFlagHasBeenClearedByTx[u8Instance] = CLEAR; 00329 00330 /* Get data */ 00331 u8Status = u8fnLINUARTGetRxData(u8Instance); 00332 } 00333 else 00334 { 00335 u8Status = UART_NO_DATA_RX; 00336 } 00337 return(u8Status); 00338 } 00339 /* 00340 ****************************************************************************** 00341 * u8fnLINUARTGetRxData 00342 ****************************************************************************** 00343 */ 00344 static uint8_t u8fnLINUARTGetRxData(uint8_t u8Instance) 00345 { 00346 /* Declare locals */ 00347 uint8_t u8Status; 00348 uint8_t u8UARTBufferSize; 00349 int8_t i8Counter; 00350 LINFLEX_t tMyLINFLEX; 00351 00352 /* Init locals */ 00353 u8Status = CLEAR; 00354 00355 /* Before anything can happen, we need to know to what instance we're */ 00356 /* going to talk to. */ 00357 tMyLINFLEX = catLINUARTInstances[u8Instance]; 00358 00359 /* Define what the buffer size for the UART is: we need this to know how */ 00360 /* many bytes we need to transfer into RAM. */ 00361 u8UARTBufferSize = (gau8LINUARTPhysicalBufferSize[u8Instance] & 0x0F); 00362 00363 if((CLEAR < u8UARTBufferSize) && (UART_PHYSICAL_BUFF_SIZE >= u8UARTBufferSize)) 00364 { 00365 for(i8Counter = CLEAR; i8Counter < u8UARTBufferSize; i8Counter++) 00366 { 00367 switch(i8Counter) 00368 { 00369 case (UART_BUFF3): 00370 { 00371 *gpu8LINUARTRxBuffer[u8Instance] = (uint8_t)tMyLINFLEX->BDRM.B.DATA7; 00372 break; 00373 } 00374 case (UART_BUFF2): 00375 { 00376 *gpu8LINUARTRxBuffer[u8Instance] = (uint8_t)tMyLINFLEX->BDRM.B.DATA6; 00377 break; 00378 } 00379 case (UART_BUFF1): 00380 { 00381 *gpu8LINUARTRxBuffer[u8Instance] = (uint8_t)tMyLINFLEX->BDRM.B.DATA5; 00382 break; 00383 } 00384 case (UART_BUFF0): 00385 { 00386 *gpu8LINUARTRxBuffer[u8Instance] = (uint8_t)tMyLINFLEX->BDRM.B.DATA4; 00387 break; 00388 } 00389 default: 00390 { 00391 u8Status = UART_INVALID_BUFFER_SIZE; 00392 break; 00393 } 00394 }; 00395 00396 /* Increment pointer & counter of bytes received */ 00397 gpu8LINUARTRxBuffer[u8Instance]++; 00398 gau8LINUARTWordsRx[u8Instance]++; 00399 } 00400 } 00401 else 00402 { 00403 u8Status = UART_INVALID_BUFFER_SIZE; 00404 } 00405 00406 return(u8Status); 00407 } 00408 /* 00409 ****************************************************************************** 00410 * u8fnLINWriteTxBuffer 00411 ****************************************************************************** 00412 */ 00413 static uint8_t u8fnLINWriteTxBuffer(const uint8_t u8Instance, 00414 const uint8_t u8UARTBufferSize) 00415 { 00416 /* Local variables */ 00417 uint8_t u8Status; 00418 uint32_t u32ValueToWrite; 00419 uint8_t u8Counter; 00420 00421 /* Init locals */ 00422 u8Status = CLEAR; 00423 u32ValueToWrite = CLEAR; 00424 00425 /* The whole register is written in one operation - we need to comply */ 00426 if((CLEAR < u8UARTBufferSize) && (UART_PHYSICAL_BUFF_SIZE > u8UARTBufferSize)) 00427 { 00428 /* Write each byte into a 32-bit word */ 00429 for(u8Counter = CLEAR; u8Counter < u8UARTBufferSize; u8Counter++) 00430 { 00431 u32ValueToWrite |= (*gpu8LINUARTTxBuffer[u8Instance] << 00432 (u8Counter * BITS_IN_BYTE)); 00433 00434 gpu8LINUARTTxBuffer[u8Instance]++; 00435 gau8LINUARTWordsTx[u8Instance]--; 00436 } 00437 00438 catLINUARTInstances[u8Instance]->BDRL.R = u32ValueToWrite; 00439 } 00440 else 00441 { 00442 u8Status = UART_INVALID_BUFFER_SIZE; 00443 } 00444 00445 return(u8Status); 00446 } 00447 /* 00448 ****************************************************************************** 00449 * u8fnWaitForUARTTxBufferToEmpty 00450 ****************************************************************************** 00451 */ 00452 uint8_t u8fnWaitForUARTTxBufferToEmpty(uint8_t u8Instance, uint32_t u32TimeOut) 00453 { 00454 /* Local variables */ 00455 uint8_t u8Status; 00456 00457 /* Init locals */ 00458 u8Status = CLEAR; 00459 00460 do 00461 { 00462 /* Wait here */ 00463 u32TimeOut--; 00464 }while((CLEAR < u32TimeOut) && \ 00465 (CLEAR != u8fnReturnLINTxISRStatus(u8Instance))); 00466 00467 /* Flag if we came out because of a time out */ 00468 if(CLEAR == u32TimeOut) 00469 { 00470 u8Status = UART_TIMEOUT; 00471 } 00472 else 00473 { 00474 /* Exit without errors */ 00475 } 00476 00477 return(u8Status); 00478 } 00479 /* 00480 ****************************************************************************** 00481 * u8fnSelectLINInstance 00482 ****************************************************************************** 00483 */ 00484 static uint8_t u8fnReturnLINSMMode(const uint8_t u8Instance) 00485 { 00486 return((uint8_t)(catLINUARTInstances[u8Instance]->LINSR.B.LINS)); 00487 } 00488 /* 00489 ****************************************************************************** 00490 * u8fnChangeSMModeLINUART 00491 ****************************************************************************** 00492 */ 00493 static uint8_t u8fnChangeSMModeLINUART(const uint8_t u8Instance, \ 00494 const uint8_t u8Mode) 00495 { 00496 uint8_t u8Status; 00497 uint8_t u8CurrentMode; 00498 LINFLEX_t tMyLINFLEX; 00499 00500 u8Status = CLEAR; 00501 00502 /* Before anything can happen, we need to know to what instance we're */ 00503 /* going to talk to. */ 00504 tMyLINFLEX = catLINUARTInstances[u8Instance]; 00505 00506 u8CurrentMode = u8fnReturnLINSMMode(u8Instance); 00507 00508 /* Switch depending on what mode we're at and where we want to go. */ 00509 /* Note that "NORMAL" mode are is flaged as "asleep" when in UART. */ 00510 if(LIN_ASLEEP == u8CurrentMode) 00511 { 00512 if(LIN_INIT == u8Mode) 00513 { 00514 tMyLINFLEX->LINCR1.B.SLEEP = CLEAR; 00515 tMyLINFLEX->LINCR1.B.INIT = TRUE; 00516 } 00517 else 00518 { 00519 u8Status = u8CurrentMode; 00520 } 00521 } 00522 else if(LIN_INIT == u8CurrentMode) 00523 { 00524 if(LIN_ASLEEP == u8Mode) 00525 { 00526 tMyLINFLEX->LINCR1.B.SLEEP = TRUE; 00527 } 00528 else if (LIN_INIT == u8Mode) 00529 { 00530 u8Status = u8CurrentMode; 00531 } 00532 else 00533 { 00534 tMyLINFLEX->LINCR1.R = (tMyLINFLEX->LINCR1.B.SLEEP & 0xFFFC) | CLEAR; 00535 //tMyLINFLEX->LINCR1.B.INIT = CLEAR; 00536 //tMyLINFLEX->LINCR1.B.SLEEP = CLEAR; 00537 } 00538 } 00539 else 00540 { 00541 u8Status = u8CurrentMode; 00542 } 00543 00544 return(u8Status); 00545 } 00546 /* 00547 ****************************************************************************** 00548 * u8fnReturnLINTxISRStatus 00549 ****************************************************************************** 00550 */ 00551 static uint8_t u8fnReturnLINTxISRStatus(uint8_t u8Instance) 00552 { 00553 00554 return((uint8_t)(catLINUARTInstances[u8Instance]->LINIER.B.DTIE)); 00555 } 00556 /* 00557 ****************************************************************************** 00558 * u8fnReturnLINRxISRStatus 00559 ****************************************************************************** 00560 */ 00561 static uint8_t u8fnReturnLINRxISRStatus(uint8_t u8Instance) 00562 { 00563 return((uint8_t)(catLINUARTInstances[u8Instance]->LINIER.B.DRIE)); 00564 } 00565 /* 00566 ****************************************************************************** 00567 * vfnEnableLINTxISR 00568 ****************************************************************************** 00569 */ 00570 void vfnEnableLINTxISR(uint8_t u8Instance, uint8_t u8Switch) 00571 { 00572 catLINUARTInstances[u8Instance]->LINIER.B.DTIE = (CLEAR < u8Switch); 00573 00574 return; 00575 } 00576 00577 /* 00578 ****************************************************************************** 00579 * vfnEnableLINRxISR 00580 ****************************************************************************** 00581 */ 00582 void vfnEnableLINRxISR(uint8_t u8Instance, uint8_t u8Switch) 00583 { 00584 catLINUARTInstances[u8Instance]->LINIER.B.DRIE = (CLEAR < u8Switch); 00585 00586 return; 00587 } 00588 /* 00589 ****************************************************************************** 00590 * vfnGenericLINTxIsr 00591 ****************************************************************************** 00592 */ 00593 static void vfnGenericLINTxIsr(uint8_t u8Instance) 00594 { 00595 /* Local variables */ 00596 LINFLEX_t tMyLINFLEX; 00597 00598 00599 /* Before anything can happen, we need to know to what instance we're */ 00600 /* going to talk to. */ 00601 tMyLINFLEX = catLINUARTInstances[u8Instance]; 00602 00603 /* Clear the flag: Note that even though we're only writing to the DTF */ 00604 /* flag, this also clears the DRF flag. We must therefore handle any */ 00605 /* pending DRF as well. */ 00606 if(tMyLINFLEX->UARTSR.B.DRF == TRUE) 00607 { 00608 gau8LINUARTRxFlagHasBeenClearedByTx[u8Instance] = TRUE; 00609 } 00610 else 00611 { 00612 gau8LINUARTRxFlagHasBeenClearedByTx[u8Instance] = CLEAR; 00613 } 00614 00615 tMyLINFLEX->UARTSR.B.DTF = TRUE; 00616 00617 /* Only transmit if we still have something in the buffer */ 00618 if(CLEAR != gau8LINUARTWordsTx[u8Instance]) 00619 { 00620 /* Place as many values in the UART buffer as possible */ 00621 (void)u8fnLINUARTSetTxData(u8Instance); 00622 } 00623 else 00624 { 00625 /* We're done transmitting. Turn interrupts off */ 00626 vfnEnableLINTxISR(u8Instance, CLEAR); 00627 00628 /* Reconfigure UART buffer size to its default value */ 00629 (void)u8fnChangeSMModeLINUART(u8Instance, LIN_INIT); 00630 tMyLINFLEX->UARTCR.B.TDFL = \ 00631 (gau8LINUARTPhysicalBufferSize[u8Instance] >> BITS_IN_NIBBLE) - 1u; 00632 (void)u8fnChangeSMModeLINUART(u8Instance, LIN_IDLE); 00633 } 00634 00635 return; 00636 } 00637 /* 00638 ****************************************************************************** 00639 * vfnLIN0TxIsr 00640 ****************************************************************************** 00641 */ 00642 void vfnLIN0TxIsr(void) 00643 { 00644 vfnGenericLINTxIsr(LIN_INSTANCE_0); 00645 return; 00646 } 00647 /* 00648 ****************************************************************************** 00649 * vfnLIN1TxIsr 00650 ****************************************************************************** 00651 */ 00652 void vfnLIN1TxIsr(void) 00653 { 00654 vfnGenericLINTxIsr(LIN_INSTANCE_1); 00655 00656 return; 00657 } 00658 /* 00659 ****************************************************************************** 00660 * vfnLIN2TxIsr 00661 ****************************************************************************** 00662 */ 00663 void vfnLIN2TxIsr(void) 00664 { 00665 vfnGenericLINTxIsr(LIN_INSTANCE_2); 00666 00667 return; 00668 } 00669 /* 00670 ****************************************************************************** 00671 * vfnLIN3TxIsr 00672 ****************************************************************************** 00673 */ 00674 void vfnLIN3TxIsr(void) 00675 { 00676 vfnGenericLINTxIsr(LIN_INSTANCE_3); 00677 00678 return; 00679 } 00680 /* 00681 ****************************************************************************** 00682 * vfnGenericLINRxIsr 00683 ****************************************************************************** 00684 */ 00685 static void vfnGenericLINRxIsr(uint8_t u8Instance) 00686 { 00687 /* Put data in array */ 00688 (void)u8fnLINUARTGetRxData(u8Instance); 00689 00690 /* Since clearing the Rx flag also clears the Tx flag, we need to check */ 00691 /* it here as well and send data if it's the case. */ 00692 if(TRUE == catLINUARTInstances[u8Instance]->UARTSR.B.DTF) 00693 { 00694 /* Only transmit if we still have something in the buffer */ 00695 if(CLEAR != gau8LINUARTWordsTx[u8Instance]) 00696 { 00697 /* Place as many values in the UART buffer as possible */ 00698 (void)u8fnLINUARTSetTxData(u8Instance); 00699 } 00700 else 00701 { 00702 /* We're done transmitting. Turn interrupts off */ 00703 vfnEnableLINTxISR(u8Instance, CLEAR); 00704 00705 /* Reconfigure UART buffer size to its default value */ 00706 (void)u8fnChangeSMModeLINUART(u8Instance, LIN_INIT); 00707 catLINUARTInstances[u8Instance]->UARTCR.B.TDFL = \ 00708 (gau8LINUARTPhysicalBufferSize[u8Instance] >> BITS_IN_NIBBLE) - 1u; 00709 (void)u8fnChangeSMModeLINUART(u8Instance, LIN_IDLE); 00710 } 00711 } 00712 else 00713 { 00714 /* Nothing */ 00715 } 00716 00717 /* Clear the flag */ 00718 catLINUARTInstances[u8Instance]->UARTSR.B.DRF = TRUE; 00719 00720 00721 00722 return; 00723 } 00724 /* 00725 ****************************************************************************** 00726 * vfnLIN0RxIsr 00727 ****************************************************************************** 00728 */ 00729 void vfnLIN0RxIsr(void) 00730 { 00731 vfnGenericLINRxIsr(LIN_INSTANCE_0); 00732 00733 return; 00734 } 00735 /* 00736 ****************************************************************************** 00737 * vfnLIN1RxIsr 00738 ****************************************************************************** 00739 */ 00740 void vfnLIN1RxIsr(void) 00741 { 00742 vfnGenericLINRxIsr(LIN_INSTANCE_1); 00743 00744 return; 00745 } 00746 /* 00747 ****************************************************************************** 00748 * vfnLIN2RxIsr 00749 ****************************************************************************** 00750 */ 00751 void vfnLIN2RxIsr(void) 00752 { 00753 vfnGenericLINRxIsr(LIN_INSTANCE_2); 00754 00755 return; 00756 } 00757 /* 00758 ****************************************************************************** 00759 * vfnLIN3RxIsr 00760 ****************************************************************************** 00761 */ 00762 void vfnLIN3RxIsr(void) 00763 { 00764 vfnGenericLINRxIsr(LIN_INSTANCE_3); 00765 00766 return; 00767 } 00768 /* 00769 ****************************************************************************** 00770 * 00771 * End of file. 00772 * 00773 ****************************************************************************** 00774 */